/* qMenu.js (qJSLib)
 
    @Summary    : qMenu Widget
    @Author     : Timothy C. Quinn
    @License    : http://www.opensource.org/licenses/mit-license.php
  
    @Dependencies:
     - qCore.js (qJSLib)
     - qBase.js (qJSLib)
     - qHtml.js (qJSLib)
     - jquery.js
   
    @Notes:
     - (none)
   
    @Todo:
     - 
*/

qMenu_StaticMembers = {
	pub_constants: {/* No not name const or it will kill IE :( */
		 TYPE_horiz: "horiz"
		,TYPE_vert: "vert"
	}
	,other: {
		 instances: []	
		,priv_isOpen: false
		,CSS_Main: {border: "1px solid #7d6340", fontSize: "80%", backgroundColor: "#FFFFEF", color: "navy"}
	    ,create: function qmw_create(jOpt){
	   		var t=this,oMW
	   		oMW = new qMenu(jOpt)
	   		return oMW
		}
		,optBox: function qmw_optBox(j){
			var h=qHtml,sClr,sBrdClr,sBgImg,sBgClr,v;
			j=j?j:{};
			sClr=(v=j.color)?v:"#ffffef";
			sBrdClr=(v=j.bordColor)?v:"#dddddd";
			sBgClr=(v=j.bgColor)?v:null;
			if(!sBgClr)sBgImg=(v=j.bgImg)?v:'hg26-003366-3c78b6.gif';
			return (
				mkE(h.TABLE, {
						_id: agetParam('j',j,'id', true, true)
						,_onclick: agetParam('j',j,'onclick', true, true)
						,_class: "optbox"
						, _style:"color: "+sClr+"; border: 1px solid "+sBrdClr+"; opacity: 0.7; filter: alpha(opacity=70)"+((v=sBgImg)?"; background-repeat: repeat-x; background-image: url("+imagePath+v+");":"; background-color: "+sBgClr)+((v=j.font)?"; "+v:"; font-size: 75%;")
					})
				 	+"\n <tr"
				 	+"\n  onmouseover=\"var o=this.parentNode.parentNode; qSetOpacity(o, 1.0); $(o).css({cursor: '"+(is.ie?"hand":"pointer")+"'});\" "
				 	+"\n  onmouseout=\"var o=this.parentNode.parentNode; qSetOpacity(o, 0.7); $(o).css({cursor: 'default'});\" "							
				 	+"\n >"
			 			+"<td style='border-right: 1px solid "+sBrdClr+"; padding: 0px 2px 1px 2px'>"+((v=j.label)?v:"Options")+"</td>"
			 			+"<td style=''>&nbsp;<img src='"+imagePath+"ddWhite2.gif' style='vertical-align: middle'>&nbsp;</td>"
					+"</tr>"
				+"</table>"
			)
		}
		,e_doc_keydown: function qmw_e_doc_keydown(e){
			var oOpened=qMenu.priv_isOpen
			if(oOpened){
				/* todo - This is where we can handle keydown events for Selects (Nice to have feature =) */
//pc(
//     "\n oOpened = "+oOpened
//    +"\n e.keyCode = "+e.keyCode
//    +"\n e:\n"+s$.pad(q$.dump(e))
//);
			}
		}
	}
}
qMenu=QWidget.extend({
	className :"qMenu"
  // Constructor
	,base_constr :function qmw_base_constr(jOpt){
//		pc(">>")
		var	t=this,aInst=qMenu.instances,v,a
		   ,h=qHtml,iW
		;
		try	{
			qObjAppend(t,qMenu_StaticMembers.pub_constants)		
			t.priv_no=aInst.length; aInst.p(t); 
			t.base({instance:t,	name:"qmw_"+t.priv_no})
			
			t.isMain=jOpt.main
			t.loadOpts=jOpt
			
			if( v=jOpt.id ){
				if(isElem(getElem(v))){qErr("id Passed in options ("+v+") already exists!!")}
				t.id=jOpt.id
			} else
				t.id="qMW"+t.priv_no
					
			t.type=jOpt.type||t.TYPE_vert
			if(t.type===t.TYPE_horiz){
				
			}else if(t.type===t.TYPE_vert){
				
			} else
				qErr("Invalid qMW Type passed ("+t.type+")")
				
		  // Process CSS Overrides
		    qObjAppend(t.cssMain, qMenu.CSS_Main);
		    if( (v=jOpt.cssMain) ){qObjAppend(t.cssMain,v)};
		    
		    t.ofsX=jOpt.ofsX
		    t.ofsY=jOpt.ofsY

			a=t.loadCommands=agetParam_arr("jOpt", jOpt, "commands", true)
			t.commands=[]
			for(var i=0;i<a.length;i++){
				t.commands.p(new qCommand(a[i]))
			}
			
			t.menuCtnr = agetParam_elem("jOpt", jOpt, "menuCtnr", false)
		
			o=t.priv_oMenu=_d.createElement("div")
			$(o)
			 	.attr({id: t.id})
			 	.addClass("qmwMain")
			 	.css(t.cssMain)
			 	.css({width: "100px"})
			 	
			o.getWidget = function qmw_getWidget(){return t}
			
			if(isDef(t.menuCtnr)){
				iW=agetParam_int("jOpt", jOpt, "width", true)
				t.menuCtnr.appendChild(o)
				$(o).css({visibility: "visible", width: iW+"px"})
			} else {
				if(t.isMain)qFloatElem.define(o);
				$(o).addClass("float")
			}
			
			if(aInst.length==1)
				_w._aDoc_KD_Ev.p("qMenu.e_doc_keydown")
				
			if(t.isMain)
				t.rebuild()
			
			if(jOpt.orphan)_d.body.appendChild(o)
			
		}catch(exc){qErr(t.className+" Base	Constructor	Failed:	",exc)}
			
//		pc("<<")
	}

    ,commands: null
    ,dispCmdCnt: -1 // <~ Number of Commands displayed
    ,loadCommands: null
    ,priv_no: -1
    ,priv_isOpen: false
    ,cssMain: {}
    ,isMain: false


   	
	,getFltElem: function qmw_getFltElem(){return this.priv_oMenu}
	,rebuild: function qmw_rebuild(jExprDat){
		var t=this,iLvl=0,oMCur,aM=[],a,aCmd,cmd,bHasExpr
		
		if(!t.isMain)qErr("rebuild can only be called for Main Menu!")
		
		aM=[[t]]
		iLvl=0
		while(true){
			a=aM[iLvl]
			for(var i=0;i<a.length;i++){oMCur=a[i]	
				aCmd=oMCur.commands
				for(var j=0;j<aCmd.length;j++){cmd=aCmd[j]
					if( sm=cmd.subMenu ){
						if(aM.length-1==iLvl)aM[iLvl+1]=[];
						aM[iLvl+1].p(sm);
					}else{
//pc("cmd.activeExpr = "+cmd.activeExpr)
						if(isDef(cmd.activeExpr)){bHasExpr=true};	
					}
				}
			}
			if(aM.length-1==iLvl){break}else{iLvl++}
		}	
		
		if(bHasExpr){
			t.priv_procMenuExpr(
				 aM
				,(jExprDat||agetParam_json	("t.loadOpts",t.loadOpts,"exprDat", true))
				,agetParam ("t.loadOpts",t.loadOpts,"exprEnv", true)
			)
		}
		
//pc(
//   "\n Menu Stack"
//  +"\n aM:\n"+s$.pad(aM.join("\n"))
//);
	  // Now Execute Builds Bottom Up
		for(var i=aM.length-1;i>-1;i--){a=aM[i]
			for(var j=0;j<a.length;j++){a[j].priv_build();}	
		}
		
	}
	,priv_procMenuExpr: function qmw_priv_procMenuExpr(aM,jExprDat,sExprEnv){
      // Load Expr Env
		try {
			eval(sExprEnv)
		}catch(x){
			qErr("Failed while evaluating Menu Expr.\n sExprEnv: '"+sExprEnv+"'",x)
		}
		var a,oM,aCmd,sm,sActiveExpr,m=jExprDat,bExpr,v
		for(var i=0;i<aM.length;i++){a=aM[i]
			for(var j=0;j<a.length;j++){
				oM=a[j]
				aCmd=oM.commands
				for(var k=0;k<aCmd.length;k++){cmd=aCmd[k]
					if( sm=cmd.subMenu ){continue}
					if( isDef(sActiveExpr=cmd.activeExpr) ){
						try {
							eval("bExpr = ("+sActiveExpr+")")
							if(!bExpr){
								if( isDef(v=cmd.disabledMsg) ){
									cmd.disabled=true
									cmd.disabledMsg=v
								} else {
									cmd.hidden=true
								}
							} else {
								cmd.hidden=cmd.disabled=false
							}
//pc(
//     "\n cmd              = "+cmd
//    +"\n sActiveExpr        = |"+sActiveExpr+"|"
//    +"\n bExpr            = "+bExpr
//    +"\n cmd.hidden       = "+cmd.hidden
//    +"\n cmd.disabled     = "+cmd.disabled
//    +"\n cmd.disabledMsg  = "+cmd.disabledMsg
//    +"\n cmd.disabledMsg    = "+cmd.disabledMsg
//);
						}catch(x){
							qErr("Failed while evaluating Menu Expr.\n activeExpr: '"+sActiveExpr+"'",x)
						}
					}
				}

			}
		}
	}
    ,priv_build: function qmw_priv_build(){
    	var t=this,qmw=t,a=t.commands,aR=[],aSel,oL=t.priv_oMenu,o,oCL,cmd
    	   ,sH="",aCE,sm,v,oTR,aSMCmd,iDCtr
    	;
		oL.innerHTML=""
		sH="<table cellpadding=0 cellspacing=0 width=100%>"
		for(var i=0;i<a.length;i++){cmd=a[i];sm=cmd.subMenu
			sH+="\n<tr class='qmwMI"+(sm?" qmwSM":"")+"'>"
					+"<td  style='' align=left>"//background-image: url("+imagePath+"/depot.gif); background-repeat: no-repeat;
						+((v=cmd.icon)
							?("<div style='background-image: url("+imagePath+v+"); background-repeat: no-repeat; opacity: 0.7; filter: alpha(opacity=70); position: absolute; float: left; left: 0px; width: 18px; height: 18px; background-position: 1px 0px'></div>")
							:""
						 )
						+"<div style='opacity: 1.5; filter: alpha(opacity=150)'>"+cmd.label+"</div>"
					+"</td>"
				+"</tr>"
		}
		oL.innerHTML=sH+"</table>"
		aCE=t.getCmdElems()

		for(var i=0;i<a.length;i++){cmd=a[i]; o=aCE[i]
			$(o)
				.attr({ind: i, id: t.id+"_"+i})
//				.bind("click", t.cmd_click)
//				.bind("mouseover", t.cmd_mouseover)
//				.bind("mouseout", t.cmd_mouseout)
//				.bind("selectstart", t.cmd_onSelectStart)/* IE Tweak */
			;
			
			assignEventListener(o, "click", t.cmd_click)
			assignEventListener(o, "mouseover", t.cmd_mouseover)
			assignEventListener(o, "mouseout", t.cmd_mouseout)
			assignEventListener(o, "selectstart", t.cmd_onSelectStart)/* IE Tweak */
//			
			if( sm=cmd.subMenu ){
				qFloatElem.define(sm.priv_oMenu,{fltPar: t.priv_oMenu})
				
				aSMCmd=sm.commands
				iDCtr=0
				for(var j=0;j<aSMCmd.length;j++){cmdSM=aSMCmd[j]
					if(!cmdSM.hidden){iDCtr++}
				}
				if(iDCtr==0){
					cmd.hidden=true
				} else {
					cmd.hidden=false
					qFloatElem.define(sm.priv_oMenu,{fltPar: t.priv_oMenu})
				}
				
			}
			
			oTR=o.parentNode
			oTR.style.display=cmd.hidden?"none":""
			if(cmd.disabled){
				$(oTR).addClass("qmwMI-dis").attr("title", cmd.disabledMsg)
			} else {
				$(oTR).removeClass("qmwMI-dis").attr("title", "")
			}
			
			o.getQMW = function cmd_getQMW(){return qmw}
			o.getSM = function cmd_getSM(){return this.getCmd().subMenu }
			o.getCmd = function qmw_getCmd(){
				var o=this
				   ,a=qmw.commands
				   ,i=$(o).attr("ind")
				;
				return a[i]
			}

		}
		t.autoWidth()
    }
    ,getCmdElems: function qmw_getCmdElems(){
    	var t=this, o=t.priv_oMenu,aCE;
    	aCE=o.getElementsByTagName("td");
    	return aCE;
    }
    ,clearSel: function qmw_clearSel(j){
    	var t=this,iInd,cmd,sm,a,v,oSel=t.selected,aCE,oSMFlt;j=j?j:{}
//pc(
//     "\n this.selected = "+((v=this.selected)?v.id:"(null)")
//    +"\n args:\n"+s$.pad(q$.dumpArgs())
//    +"\n stack:\n"+s$.pad(getStackTrace())
//);
    	
      
		aCE=t.getCmdElems();
		for(var i=0;i<aCE.length;i++){
//pc(
//     "\n aCE[i] = "+aCE[i]
//    +"\n aCE[i].id = "+aCE[i].id
//);
		  /* Clear mousouts */
			if(j.mov)aCE[i]._e_mou=function cmd_e_mou_null(){}
			
			if(oSel!=j.oECur)$(aCE[i]).removeClass('qmwMI-sel');
    			
//    			pc(aCE[i]._toMOU)
//    			clearTimeout(aCE[i]._toMOU);
    	}

//pc(
//     "\n t = "+t
//    +"\n j.mou = "+j.mou
//    +"\n j.mov = "+j.mov
//    +"\n j.smOpen = "+j.smOpen
//    +"\n j.oECur = "+(j.oECur?j.oECur.id:"(null)")
//    +"\n stack:\n"+s$.pad(getStackTrace())
//);
	  /* close sm */
	  	if(j.mov && oSel==j.oECur)return;

    	if(oSel){
//pc(
//	"\n oSel = "+(oSel?oSel.id:"(null)")
//   +"\n oSel.getSM() = "+oSel.getSM()
//)
    		$(oSel.parentNode).removeClass('qmwMI-sel');
    		if( sm=oSel.getSM() ){
    			oSMFlt=sm.getFltElem()
//pc(
//	"\n oSMFlt = "+oSMFlt.id
//   +"\n oSMFlt.isOpen() = "+oSMFlt.isOpen()
//)
    			if(oSMFlt.isOpen())oSMFlt.close();
	    	}
		}
    }
	,cmd_mouseover: function qmw_cmd_mouseover(e){//pc("called - this = "+this.id)
		var oS,qmw,oTR,iInd,cmd,sm,a,v;
		try {
			oS=this;
			qmw=oS.getQMW()
			qmw.clearSel({mov: true, oECur: oS})
			try {qmw.getFltElem()._cto({noCasc: true});}catch(x){};
			clearTimeout(oS._toMOU)
			qmw.movLast=q$.getTS()
			
			a=qmw.commands;oTR=oS.parentNode;iInd=$(oS).attr("ind");cmd=a[iInd];sm=cmd.subMenu;
				
//pc(
//     "\n called - this = "+this.id
////    +"\n stack:\n"+s$.pad(getStackTrace())
//);
				
			qmw.selected=oS;
//pc(
//     "\n oS = "+oS
//    +"\n oS.id = "+oS.id
//    +"\n oS._toMOU = "+oS._toMOU
//);
			$(oTR).addClass("qmwMI-sel")
				
//pc(
//     "\n oS = "+oS
//    +"\n oS._toMOU = "+oS._toMOU
//    +"\n oTR = "+oTR
//    +"\n oTR.id = "+oTR.id
//    +"\n oTR.innerHTML = "+oTR.innerHTML
//);
			if(sm){
				oSMFlt=sm.getFltElem()
				oSMFlt._cto();
				oSMFlt.cmdParElem=oS
				oSMFlt.open({
					parent: oS
				   ,position: qHtml.POS_TR
				   ,ofsX: (isNum(v=sm.ofsX)?v:0)
				   ,ofsY: (isNum(v=sm.ofsY)?v:0)
				   ,noSelfClose: true
				});
				
			}
			
		}catch(x){debugErr(x)}
	}
	,cmd_mouseout: function qmw_cmd_mouseout(e){//pc("called - this = "+this.id)
		var oS,t,oTR,iInd,cmd,sm,a,iDelay,oSMFlt;
		try {
			oS=this;
			t=oS.getQMW()

//			if(sm&&sm.priv_oMenu.isOpen())return
			oS._e_mou=function cmd_e_mou(){
				oS=this;
				t=oS.getQMW()
				a=t.commands;oTR=oS.parentNode;iInd=$(oS).attr("ind");
//pc(
//     "\n oS = "+oS
//    +"\n oS.id = "+oS.id
//    +"\n iInd = "+iInd
//    +"\n a = "+a
//    +"\n a.length = "+a.length
//    +"\n a[iInd] = "+a[parseInt(iInd)]
//);
				
				cmd=a[iInd];sm=cmd.subMenu;

//pc(
//     "\n called - this = "+this.id
////    +"\n stack:\n"+s$.pad(g//pc("HERE - sm = "+sm)etStackTrace())
//);
//pc(
//     "\n oS = "+oS
//    +"\n oS.id = "+oS.id
//);
				
//				t.clearSel({mou: true, oECur: oS});

    			if(sm){
    				iDelay=(q$.getTS()-t.smFocusTS)
//pc(
//     "\n q$.getTS() = "+q$.getTS()
//    +"\n iDelay = "+iDelay
//    +"\n isNum(iDelay) = "+isNum(iDelay)
//    +"\n t.smFocusTS = "+t.smFocusTS
//    +"\n (q$.getTS()-t.smFocusTS) = "+(q$.getTS()-t.smFocusTS)
//);
    				if( !isNum(iDelay)||(q$.getTS()-t.smFocusTS)>200 ){
//pc("here")		
	    				$(oTR).removeClass('qmwMI-sel');
    					oSMFlt=sm.getFltElem()
    					if(oSMFlt.isOpen())oSMFlt.startClose({delay: 500, noCasc: true});

					}
				} else {
					$(oTR).removeClass('qmwMI-sel');
				}
					

//				pc("done")
			}
			oS._toMOU=setTimeout("agetElem('"+oS.id+"')._e_mou()",5)
			
//pc(
//     "\n oS = "+oS
//    +"\n oS.id = "+oS.id
//    +"\n oS._toMOU = "+oS._toMOU
//);
		}catch(x){debugErr(x)}
	}


	,cmd_onSelectStart: function qmw_cmd_onSelectStart(e){return false }
	,cmd_click: function qmw_cmd_click(e){
		var oS=this,qmw=oS.getQMW(),a=qmw.commands,iInd=$(oS).attr("ind"),cmd=a[iInd],sm;
//pc(
//     "\n oS = "+oS
//    +"\n qmw = "+qmw
//    +"\n a = "+a
//    +"\n iInd = "+iInd
//    +"\n cmd:\n"+s$.pad(qDumpObj(cmd))
//);
		if(cmd.disabled){
			alert("Command Disabled\n\n"+cmd.disabledMsg)	
			return
		}

		if( sm=cmd.subMenu ){
//pc(
//     "\n sm.ofsX = "+sm.ofsX
//    +"\n sm.ofsY = "+sm.ofsY
//    +"\n (isNum(v=sm.ofsX)?v:0) = "+(isNum(v=sm.ofsX)?v:0)
//    +"\n (isNum(v=sm.ofsY)?v:0) = "+(isNum(v=sm.ofsY)?v:0)
//);

		} else {
			if(v=cmd.script){
				try{
					eval(v)
				}catch(x){qErr("Error Evaluating Script \""+v+"\"",x)}
			} else if (v=cmd.handler){

				try{
					v(e, oS, cmd, cmd.hArgs)
				}catch(x){
					qErr("Error On qCommand Handler for Command "+cmd,x)
				}
			}

			try {qmw.priv_oMenu.close({casc: true})}catch(x){}
		}

	}
	,smIsOpening: function qmw_smIsOpening(oCPE){//pc("called, oCPE.id = "+oCPE.id)
		var t=this
		t.smOpen=oCPE
		t.smOpenTS=q$.getTS()
	}
	,smIsClosing: function qmw_smIsClosing(oCPE,iTSCall){//pc("called, oCPE.id = "+oCPE.id)
		var t=this
		t.smOpen=null
		$(oCPE.parentNode).removeClass('qmwMI-sel');
//pc(
//     "\n                    t = "+t
//    +"\n              iTSCall = "+iTSCall
//    +"\n           t.tsFltMOV = "+t.tsFltMOV
//    +"\n (t.tsFltMOV-iTSCall) = "+(t.tsFltMOV-iTSCall)
//    +"\n (iTSCall>t.tsFltMOV) = "+(iTSCall>t.tsFltMOV)
//);
		if((iTSCall-300)>t.tsFltMOV){
			t.getFltElem().startClose({delay: 150, noCasc: true, tsCall: iTSCall});
		}
	}
	,smHasFocus: function qmw_smHasFocus(oCPE){//pc("called, oCPE.id = "+oCPE.id)
		var t=this,qmwPar
		t.smFocusTS=q$.getTS()
		try {t.getFltElem()._cto({noCasc: true});}catch(x){}
		oCPE._e_smhf=function cmd__e_smhf(){
			$(oCPE.parentNode).addClass('qmwMI-sel');
		};setTimeout("agetElem('"+oCPE.id+"')._e_smhf()",50)
	}
  /* qFlt MOV Handler */
	,fltMOV: function qmw_fltMOV(){
//pc("CALLED - "+this)

		var t=this,oCPE=t.getFltElem().cmdParElem,qmwPar;
		t.tsFltMOV=q$.getTS()
//pc(
//     "\n t.priv_oMenu = "+t.priv_oMenu.id
//    +"\n t.getFltElem() = "+t.getFltElem().id
//    +"\n oCPE = "+(oCPE?oCPE.id:"(null)")
//);
		if(oCPE && oCPE.getQMW){
			qmwPar=oCPE.getQMW()	
			qmwPar.smHasFocus(oCPE)
		} 
		
	}
    ,isOpening: function qmw_isOpening(){
//    	pc("called")
        var t=this,oFlt=t.getFltElem(),oFltPar=oFlt.fltPar,qmwPar,oCPE;
        t.priv_isOpen=true;
//pc(
//     "\n t = "+t
//    +"\n oFlt = "+oFlt
//    +"\n oFlt.id = "+oFlt.id
//    +"\n oFlt.innerHTML = "+oFlt.innerHTML
//    +"\n oFltPar = "+oFltPar
//    +"\n oFltPar.id = "+oFltPar.id
//    +"\n oFltPar.innerHTML = "+oFltPar.innerHTML
//);
      
        t.autoWidth()
        t.clearSel()
        oCPE=oFlt.cmdParElem
        if(oCPE){
        	qmwPar=oCPE.getQMW()	
        	qmwPar.smIsOpening(oCPE)
        }
        
    }
	,isClosing: function qmw_isClosing(iTSCall){
		var t=this,oFlt=t.getFltElem(),oFltPar=oFlt.fltPar,qmwPar,oCPE;

   		t.priv_isOpen=false;
        oCPE=oFlt.cmdParElem
        if(oCPE){
        	qmwPar=oCPE.getQMW()	
        	qmwPar.smIsClosing(oCPE,iTSCall)
        }
        t.clearSel()
   	}
	,autoWidth: function qmw_autoWidth(){
    	var t=this,qmw=t,a=t.commands,aR=[],aSel,oL=t.priv_oMenu,o,iMW=-1;
    	if(t.aqSet)return
		a=oL.getElementsByTagName("div")
		for(var i=0;i<a.length;i++){o=a[i]
//pc(
//	"\n\n"
//   +"\n o = "+o
//   +"\n o.offsetWidth = "+o.offsetWidth
//   +"\n\n"
//)
			if(o.offsetWidth>iMW)iMW=o.offsetWidth;
		}
//pc("iMW = "+iMW)
		if(iMW>0){
			$(oL).css({width: (iMW+42)+"px"})
			t.aqSet=true
		}
	}
    
    ,toString: function(){var t=this; return "["+t.className+" ("+this.priv_no+")]"}
	,constructor: function qMenu(jOpt)	{this.base_constr(jOpt)}
	
});/*Inherit Static Members*/qObjAppend(qMenu,qMenu_StaticMembers.pub_constants);qObjAppend(qMenu,qMenu_StaticMembers.other)

function qCommand(jOpt){
	var t=this;
	t.label = agetParam("jOpt", jOpt, "label", true)
	t.handler = agetParam_func("jOpt", jOpt, "handler", false)
	t.icon = jOpt.icon
	t.activeExpr = jOpt.activeExpr
	t.disabledMsg = jOpt.disabledMsg
	if(isDef(t.handler)){
		t.hArgs = agetParam_obj("jOpt", jOpt, "hArgs", false)
	} else {
		t.script = agetParam("jOpt", jOpt, "script", false)	
		if(!t.script){
			t.subMenu = agetParam_obj("jOpt", jOpt, "subMenu", true)	 
		} else {
			qErr("Param Missing, at least one of handler, script or subMenu is required")	
		}
	}
};
qObjAppend(qCommand.prototype,{
	isSelected: false,text: null,value: null
   ,toString: function(){var t=this; return "[Object qCommand] ("+s$.pad("label = "+t.label)+")"}
})